<!--混凝土拌和站---动态监控--实时监控-->
<!--
 * @Author: 卡卡 1071780426@qq.com
 * @Date: 2022-12-02 13:13:25
 * @LastEditors: 陈妮娜 969682281@qq.com
 * @LastEditTime: 2024-03-22 16:24:17
 * @FilePath: \backstage - 副本\src\views\aa.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
  <div class="department" id="department">
    <!-- 左侧部门管理 -->
    <div class="structureTree" v-if="treelength">
      <div class="structureTree_title">
        <div>组织机构</div>
        <div>
          <!-- <el-checkbox v-model="checked" @change="see()">查看下级</el-checkbox> -->
        </div>
      </div>
      <tree
        :treeData="treeData"
        :checkData="checkData"
        nodeKey="fCompanyid"
        @getTreeInfo="handleNodeClick"
        :defaultProps="defaultProps"
      >
      </tree>
    </div>
    <!-- 右侧 -->
    <div class="department_right">
      <!-- 机构名称 -->
      <el-breadcrumb :title="showName"></el-breadcrumb>
      <!-- 顶部导航栏 -->
      <div class="mechanism_nav">
        <!-- 左侧 -->

        <div class="mechanism_nav_left" style="width: 100%">
          <vDatePicker
            :defaultDate="value2"
            @selectPickDate="selectTime"
            width="215px !important"
          >
          </vDatePicker>
          <!-- <el-date-picker @change="selectTime" v-model="value2" type="daterange" align="right" unlink-panels
                                                                                                                                                        range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" :picker-options="pickerOptions"
                                                                                    format="yyyy-MM-dd" value-format="yyyy-MM-dd">
                                                                                </el-date-picker> -->
          <el-select
            class="selectQd"
            style="width: 100px"
            v-model="getList.strengthgrade"
            placeholder="强度等级"
            @change="yj_searchForm(getList)"
          >
            <el-option
              v-for="v in strengthGradeDataList"
              :key="v.fItemName"
              :label="v.fItemName"
              :value="v.fItemValue"
            >
            </el-option>
          </el-select>
          <input
            class="projectBW"
            type="text"
            placeholder="工程名称/工程部位"
            v-model="getList.keyWord"
          />
          <el-button
            type="primary"
            icon="el-icon-search"
            size="small"
            @click="yj_searchForm(getList)"
            >查询
          </el-button>
        </div>
        <!-- 顶部按钮 -->
        <div class="print"></div>
      </div>

      <!-- 表格 -->
      <div class="text_table">
        <!-- <div :id="('select' + index)" v-for="(item, index) in tableData" :key="index">12</div> -->
        <tableData
          :height="navigatepageNums > 1 ? 'calc(100% - 50px)' : '100%'"
          :config="table_config"
          :dataList="tableData"
          :loading="listLoading"
          @selection-change="selectionChange"
          @sort-change="sortChange"
          @click-change="rowChange"
          :page="getList.page"
          :pageSize="getList.pageSize"
        />

        <pagination
          v-if="navigatepageNums > 1"
          :info="queryCriteriaData"
          :treelength="treelength"
          :total="queryCriteriaData.total"
          :pageNum.sync="getList.page"
          :limit.sync="getList.pageSize"
          @pagination="yj_searchForm(getList)"
        />
      </div>
    </div>
  </div>
</template>
  
<script>
import tree from "@/components/public/el-trees"; //左侧机构树
import TableData from "@/components/HntManage/el-tables"; //主页面列表
import Pagination from "@/components/public/el-pagination"; //主页面分页
import elBreadcrumb from "@/components/public/el-breadcrumb.vue"; //面包屑
import vDatePicker from "@/components/public/v-DatePicker";

import formJs from "./regexDetail.js"; //新增弹框配置项
import {
  getUserCompanyTreeList, //左侧机构树接口
  getMaterialAmountList, //主页面列表接口
} from "@/api/request.js";
// import { statusType } from '@/utils/config';//配置项
export default {
  name: "materialConsumption",
  data() {
    return {
      name: "materialConsumption", //按钮配置页面代号
      // yj_view: null,//查看按钮是否显示
      formObj: formJs.formObj, //新增编辑配置参数
      formData: {}, //新增编辑向后台传递对象
      navigatepageNums: null, //是否显示分页
      queryCriteriaData: {}, //分页
      strengthGradeDataList: formJs.strengthGradeDataList,
      level: [],
      earlyWarning: [],
      bhzDataList: [], //拌合站

      bhjDataList: [], //拌合机
      value2: "", //主页面日期筛选绑定值

      xlsxName: null,
      // 列表配置项
      table_config: formJs.table_config,
      tableData: [], //表格列表数据列表
      tableDatas: [], //导出所有数据

      materialData: [], //材料用量列表
      highlightBd: true, //左侧机构树停留背景色

      treelength: false, //左侧树显示隐藏
      checked: true, //查看下级按钮
      showName: "未选择公司",
      dialogHeight: "470px", //弹框高度
      fId: null, //点击当前列表数据fId
      listLoading: false, //列表数据加载loading
      loadingEditDialog: false, //弹框loading
      dialogEditVisible: false, //新增弹框是否显示
      // 列表给后端传参
      getList: {
        fCompanyid: "", // 施工标段id
        startDates: "", // 开始时间
        endDates: "", // 截至时间
        beginDates: "", //上传--开始
        overDates: "", // 上传--结束
        strengthgrade: "", // 强度等级
        stationId: "",
        machineId: "", // 拌和机编号
        keyWord: "", // 工程部位/工程名称 模糊条件
        page: 1, // 当前页码
        pageSize: 20, // 每页显示条数
        warningLevel: "", // 预警等级
        fCloseoperation: "", // 闭合状态
      },

      companyTree: "", //所有数据
      treeData: [], //左侧树状图数据

      // 左侧机构树
      defaultProps: {
        children: "children",
        label: "fShortname",
      },
      checkData: [],
      userInfo: {}, //登录用户
      treeText: {
        //树状图参数
        companyId: null,
        userId: null,
        text: null,
      },
    };
  },
  components: {
    vDatePicker,
    tree, //左侧组织机构数
    TableData, //主页面列表
    elBreadcrumb, //面包屑

    Pagination, //分页
    // selects,//下拉框
  },
  mounted() {
    this.userInfo = JSON.parse(sessionStorage.getItem("userInfo"));
    // var id = JSON.parse(sessionStorage.getItem("treeCheck"))
    // if (JSON.parse(sessionStorage.getItem("getList"))) {
    //     this.getList = JSON.parse(sessionStorage.getItem("getList"))
    // }
    if (JSON.parse(sessionStorage.getItem("treeCheck"))) {
      var id = JSON.parse(sessionStorage.getItem("treeCheck"));
      this.checkData = [id.fCompanyid];
    }
    // this.checkData = [id.fCompanyid];

    this.getTree();
    this.btnRole(this.name);
    this.getDate();
  },
  methods: {
    btnRole(name) {
      // 按钮权限
      var btnList = [];
      var ModuleList = JSON.parse(sessionStorage.getItem("ModuleList"));
      if (ModuleList.length > 0) {
        ModuleList.map((item) => {
          if (item.fEncode == name) {
            btnList = item.modulebuttonList;
          }
        });
        var btnStr = [];
        btnList.map((item) => {
          btnStr.push(item.fEncode);
        });
        // this.yj_view = btnStr.includes("yj_view");
      } else {
        // this.yj_view = true;
      }
    },
    // 点击当前行
    rowChange(val) {
      console.log(val);
    },
    // 左侧树结构
    getTree() {
      this.treeText = {
        companyId: this.userInfo.companyId,
        userId: this.userInfo.userId,
        text: "1", // 0其他  1 砼拌合站 2水稳 3沥青
      };
      getUserCompanyTreeList(this.treeText)
        .then((res) => {
          if (res.errcode == 0) {
            var companyTree = res.data.userCompanyTreeList;
            this.treeData = this.commonJs.tranListToTreeData(companyTree);

            if (this.treeData[0].children == undefined) {
              this.treelength = false; //左侧组织机构是否显示
            } else {
              this.treelength = true;
            }
            if (this.checkData[0]) {
              this.showName = JSON.parse(
                sessionStorage.getItem("treeCheck")
              ).fShortname;

              this.getList.fCompanyid = this.checkData[0];
            } else {
              this.showName = this.treeData[0].fShortname; //当前点击组织机构名称
              this.checkData[0] = this.treeData[0].fCompanyid;
              this.getList.fCompanyid = this.treeData[0].fCompanyid; //当前点击组织机构ID
            }

            this.yj_searchForm(this.getList); // 调用主页面列表接口
            // 列表
          } else {
            this.$message.error(res.msg);
            // this.$message.error("获取组织机构失败");
            return false;
          }
        })
        .catch(() => {
          return false;
        });
    },

    // 点击左侧机构树
    handleNodeClick(data) {
      this.showName = data.fShortname; //顶部显示机构名
      if (JSON.parse(sessionStorage.getItem("getList"))) {
        var datas = JSON.parse(sessionStorage.getItem("getList"));
        this.getList.fCompanyid = data.fCompanyid;
        this.value2 = [datas.startDates, datas.endDates];
      } else {
        this.getList.fCompanyid = data.fCompanyid;
        this.getList.startDates = this.common.getDay(-6) + " " + "00:00:00"; // 开始时间
        this.getList.endDates = this.common.getDay(0) + " " + "23:59:59"; // 截至时间
        this.getList.strengthgrade = ""; // 强度等级

        this.value2 = [
          this.common.getDay(-6) + " " + "00:00:00",
          this.common.getDay(0) + " " + "23:59:59",
        ];
      }
      this.getList.beginDates = ""; // 上传---开始时间
      this.getList.overDates = ""; // 上传---截至时间
      this.getList.page = 1;

      this.yj_searchForm(this.getList);
    },
    // 获取列表数据
    yj_searchForm(data) {
      this.listLoading = true;
      window.sessionStorage.setItem("getList", JSON.stringify(data));
      getMaterialAmountList(data)
        .then((res) => {
          if (res.errcode == 0) {
            var that = this;
            that.listLoading = false;
            that.tableData = res.data.pageInfo.list;
            this.queryCriteriaData = res.data.pageInfo; //分页信息
            // this.yj_searchForms(this.getList)

            this.navigatepageNums =
              this.queryCriteriaData.navigatepageNums.length;
            // this.downloadExcel()
          } else {
            this.$message.error(res.msg);
            return false;
          }
        })
        .catch((error) => {
          console.log(error);
        });
    },
    // 时间间隔
    selectTime(e) {
      if (e[0] != "" && e[1] != "") {
        this.getList.startDates = e[0] + " " + "00:00:00"; // 开始时间
        this.getList.endDates = e[1] + " " + "23:59:59"; // 截至时间
      } else {
        this.getList.startDates = ""; // 开始时间
        this.getList.endDates = ""; // 截至时间
      }
      this.yj_searchForm(this.getList);
    },

    getDate() {
      if (JSON.parse(sessionStorage.getItem("getList"))) {
        this.getList = JSON.parse(sessionStorage.getItem("getList"));
        this.getList.page = 1;
        this.value2 = [this.getList.startDates, this.getList.endDates];
        this.xlsxName =
          this.getList.startDates +
          "至" +
          this.getList.endDates +
          "混凝土拌和站记录数据";
      } else {
        this.getList.startDates = this.common.getDay(-6) + " " + "00:00:00"; // 开始时间
        this.getList.endDates = this.common.getDay(0) + " " + "23:59:59"; // 截至时间
        this.value2 = [
          this.common.getDay(-6) + " " + "00:00:00",
          this.common.getDay(0) + " " + "23:59:59",
        ];
        this.getList.beginDates = ""; // 上传---开始时间
        this.getList.overDates = ""; // 上传---截至时间
        this.xlsxName =
          this.common.getDay(-6) +
          "至" +
          this.common.getDay(0) +
          " " +
          "23:59:59" +
          "混凝土拌和站记录数据";
      }
    },
    // 获取页面容器高度
    getHeight() {
      // var h = document.documentElement.clientHeight; //获取页面可见高度
      // this.dialogHeight = h * 0.50 + "px";
    },
    // 多选方法
    selectionChange() {},
    // 排序方法
    sortChange() {},
  },
};
</script>
  
<style scoped>
.printTables {
  background: #fff;
  display: flex;
  justify-content: end;
  padding: 5px;
  margin-top: 10px;
}

.dialogBody {
  padding: 3px 20px;
  height: 80%;
  overflow-y: auto;
}

.baseTitle {
  /* border: 1px solid #0c204d; */
  border-bottom: 1px solid #0c204d;

  height: 30px;
  line-height: 30px;
  position: relative;
  padding-left: 15px;
}

.baseTitle::after {
  display: block;
  content: "";
  height: 30px;
  width: 5px;
  position: absolute;
  left: 0;
  top: 0;
  background: #0c204d;
}
</style>